package com.yqy.spring.bank.dao.impl;

import com.yqy.spring.bank.dao.AccountDao;
import com.yqy.spring.bank.pojo.Account;
import jakarta.annotation.Resource;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {
    //byName赋值
    @Resource(name="jdbcTemplate")
   private JdbcTemplate jdbcTemplate;
    @Override
    public Account selectById(String actId) {
        String sql="select actID,balance from t_act where actId=?";
        Account account = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Account.class), actId);
        return account;
    }
    @Override
    public int updateAccount(Account account) {
        String sql="update t_act set balance=? where actId=?";
        int count = jdbcTemplate.update(sql, account.getBalance(), account.getActId());
        return count;
    }

    @Override
    public int insert(Account act) {
        String sql = "insert into t_act values(?,?)";
        return jdbcTemplate.update(sql,act.getActId(),act.getBalance());
    }
}
